package com.chen.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NioTest4 {

    public static void main(String[] args) throws Exception {
        FileOutputStream fos = new FileOutputStream("out2.txt");
        FileInputStream fis = new FileInputStream("in.txt");
        FileChannel inChannel = fis.getChannel();
        FileChannel outChannel = fos.getChannel();
        ByteBuffer buf = ByteBuffer.allocate(1024);
        while (true) {
            buf.clear();//
            System.out.println("once start....");
            //将数据从通道读入缓冲区
            int read = inChannel.read(buf);
            if (-1 == read) {
                break;
            }
            buf.flip();
            outChannel.write(buf);
            System.out.println(buf.position());
            System.out.println("once end ....");
        }
    }

}
